<template>
	<view>
		<view class="size-48 bold ml-50 mt-170">
			欢迎登录
		</view>
		<view class="flex_l row mt-96">
			<image src="../../static/user.png" mode=""></image>
			<input type="text" v-model="form.account" placeholder="请输入账号">
		</view>
		<view class="flex_l row">
			<image src="../../static/pass.png" mode=""></image>
			<input type="text" v-model="form.password" placeholder="请输入密码">
		</view>
		<view class="btn" @click="login">登录</view>
		<view class="footer center">
			<image src="../../static/s_ed.png" class="img" mode=""></image>
			<view>阅读并同意<text @click="navto('/pages/user/xieyi/xieyi?type=doctor&title=用户协议')">《用户协议》</text>和<text @click="navto('/pages/user/xieyi/xieyi?type=privacy&title=隐私协议')">《隐私协议》</text></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					account:'',
					password:''
				}
			};
		},
		methods:{
			navto(url){
				uni.navigateTo({
					url
				})
			},
			login(){
				if(!uni.$u.test.mobile(this.form.account)) return this.$utils.showToast('手机号格式错误')
				if(this.password == '') return this.$utils.showToast('请输入密码')
				uni.showLoading({
					title:'登录中...'
				})
				this.$api.login(this.form).then(res=>{
					uni.hideLoading()
					if(res.code == 1){
						this.$utils.showToast('登录成功')
						uni.setStorageSync('token',res.data.userinfo.token)
						uni.setStorageSync('userInfo', res.data.userinfo)
						// this.$store.commit('getUserInfo', res.data.userinfo)
						setTimeout(function(){
							uni.switchTab({
								url:'/pages/index/index'
							})
						},1500)
					}else{
						this.$utils.showToast('登录失败')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.btn{
	width: 630rpx;
	margin: 160rpx auto 0;
}
.img{
	width: 30rpx;
	height: 30rpx;
	background: #F1F1F1;
	margin-right: 20rpx;
	border-radius: 50%;
}
.footer{
	width: 100%;
	position: fixed;
	bottom: 60rpx;
	font-size: 24rpx;
	text{
		color: #882027;
	}
}
.row{
	width: 630rpx;
	height: 100rpx;
	background: #F8F8F8;
	border-radius: 100rpx 100rpx 100rpx 100rpx;
	margin: 30rpx auto 0;
	padding: 30rpx;
	image{
		width: 40rpx;
		height: 40rpx;
	}
	input{
		flex: 1;
		font-size: 28rpx;
		margin-left: 20rpx;
	}
}
</style>
